def isPrime(b):
    if b == 1: return False
    test = True
    k = b - 1
    while k > 1:
        if not b % k:
            test = False
            break
        k -= 1
    return test

c = input()
r = []
for i in range(len(c) + 1):
    for k in range(i, len(c) + 1):
        if i == k:
            continue
        b = int(c[i:k])
        if isPrime(b):
            r += [b]
print(max(r)if r else 0)